package com.yn.admin.zy;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yn.common.model.zy.TDeviceInfoDO;
import com.yn.common.page.BasePage;
import com.yn.common.request.sc.PageParamRequest;
import com.yn.common.response.sc.BaseResult;
import com.yn.service.zy.DeviceRentOrderDetailService;
import com.yn.service.zy.DeviceRentOrderService;
import com.yn.service.zy.TDeviceInfoService;
import com.yn.service.zy.model.dto.DeviceRentOrderDTO;
import com.yn.service.zy.model.dto.TDeviceInfoDTO;
import com.yn.service.zy.model.dto.TDeviceInfoInDTO;
import com.yn.service.zy.model.query.DeviceRentOrderQuery;
import com.yn.service.zy.model.query.TDeviceInfoQuery;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName: DeviceManageController
 * @Description: 租赁设备管理Controller
 * @Author: ym
 * @Date: 2025/5/8 15:54
 **/
@RestController
@RequestMapping("/devicemanage")
public class DeviceManageController {

    @Resource
    private TDeviceInfoService deviceInfoService;

    @Resource
    private DeviceRentOrderService deviceRentOrderService;

    @Resource
    private DeviceRentOrderDetailService  deviceRentOrderDetailService;

    /**
     * 分页查询设备信息列表
     * @param query 查询参数
     * @param basePage 分页参数
     * @return 设备信息列表
     */
   /* @RequestMapping("/list-page")
    public BaseResult listPage(TDeviceInfoQuery query, BasePage basePage) {
        return BaseResult.success(deviceInfoService.listPage(query, basePage));
    }*/

    /**
     * 分页查询设备信息列表
     * @param query 查询参数
     * @param pageRequest 分页参数
     * @return 设备信息列表
     */
    @GetMapping("/list-page")
    public BaseResult<BasePage<TDeviceInfoDTO>> listPage1(TDeviceInfoQuery query, PageParamRequest pageRequest) {
        return BaseResult.success(deviceInfoService.listPage1(query, pageRequest));
    }

    /**
     * 保存设备信息
     * @param deviceInfoInDTO 设备信息入参
     */
    @PutMapping("/save")
    public BaseResult save(@RequestBody TDeviceInfoInDTO deviceInfoInDTO) {
        TDeviceInfoDO tDeviceInfoDO = TDeviceInfoInDTO.transform(deviceInfoInDTO);

        return BaseResult.success(deviceInfoService.saveOrUpdate(tDeviceInfoDO));
    }

    /**
     * 删除设备信息
     * @param deviceInfoId 设备信息id
     */
    @PutMapping("/delete")
    public BaseResult delete(@ApiParam(value = "设备信息id") @RequestParam(value = "deviceInfoId") Integer deviceInfoId) {

        return BaseResult.success(deviceInfoService.delete(deviceInfoId));
    }

    /**
     * 分页查询设备租赁订单列表
     * @param query 查询参数
     * @param basePage 分页参数
     * @return 设备租赁订单列表
     */
 /*   @RequestMapping("/order/list-page")
    public BaseResult orderListPage(DeviceRentOrderQuery query, BasePage basePage) {
        IPage<DeviceRentOrderDTO> deviceRentOrderDTOIPage = deviceRentOrderService.listPage(query, basePage);
        return BaseResult.success(deviceRentOrderService.listPage(query, basePage));
    }*/

    /**
     * 分页查询设备租赁订单列表
     * @param query 查询参数
     * @param pageRequest 分页参数
     * @return 设备租赁订单列表
     */
    @RequestMapping("/order/list-page")
    public BaseResult<BasePage<DeviceRentOrderDTO>> orderListPage1(DeviceRentOrderQuery query, PageParamRequest pageRequest) {
        return BaseResult.success(deviceRentOrderService.listPage1(query, pageRequest));
    }

    /**
     * 获取订单详情
     * @param orderId 设备租赁订单id
     */
    @GetMapping("/order/detail")
    public BaseResult getOrderDetail(@ApiParam(value = "设备租赁订单id") @RequestParam(value = "orderId") Integer orderId) {
        return BaseResult.success(deviceRentOrderDetailService.getOrderDetail(orderId));
    }
}
